home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 87 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: lyra.csx.cam.ac.uk!nmm1
  2. From: nmm1@cus.cam.ac.uk (Nick Maclaren)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Undefined result vs. int's holding undefined values.
  5. Date: 12 Jan 1996 13:52:20 GMT
  6. Organization: University of Cambridge, England
  7. Message-ID: <4d5p2k$p6d@lyra.csx.cam.ac.uk>
  8. References: <4ck70b$rd7@news.informix.com> <oZA8wQ9ytpjN084yn@csn.net> <4cs460$d6e@news.informix.com> <DKyIx1.1qr@ukpsshp1.serigate.philips.nl> <DL2CFs.FG0@harlequin.co.uk>
  9. NNTP-Posting-Host: ursa.cus.cam.ac.uk
  10.  
  11. In article <DL2CFs.FG0@harlequin.co.uk>, daveb@harlqn.co.uk (Dave Berry) writes:
  12. |> baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes) writes:
  13. |> >Daniel Wood (dwood@informix.com) wrote:
  14. |> >: Do any machines exist which actually explode when you add two number together
  15. |> >: such that the result would exceed MAXINT? :-)  Get practical!
  16. |> >
  17. |> >VAXes
  18. |> >If you set the apropriate bit in the process status word then integer overflow
  19. |> >causes a trap.
  20. |> 
  21. |> The SPARC and MIPS processors also have integer instructions that trap on
  22. |> overflow.
  23.  
  24. Not to say the IBM 370 and numerous others.  In any case, it isn't
  25. difficult to compile in reasonably efficient software checks.  But,
  26. as others have pointed out, that isn't the issue.
  27.  
  28. Most compilers (whether C, Fortran or other) do not generate code
  29. that will trigger the trap.  On the IBM 370, several of them did
  30. so more by accident than design, and so would trap on addition but
  31. not multiplication!  Even those that did it 'properly' often left
  32. it out of conversions and I/O.
  33.  
  34. Some systems have a process flag that triggers whether integer
  35. overflow causes an exception or not.  Write a bit of assembler
  36. that flips that bit and trying running a few programs - you will
  37. probably find that valid array indexing fails or the run-time
  38. system dies horribly (e.g. in I/O conversion).
  39.  
  40. I would like this feature very much, but I don't expect to see it
  41. come back into most Fortran systems, let alone C ones!  But the
  42. standard definitely allows it (for signed values and many or most
  43. conversions).
  44.  
  45.  
  46. Nick Maclaren,
  47. University of Cambridge Computer Laboratory,
  48. New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
  49. Email:  nmm1@cam.ac.uk
  50. Tel.:  +44 1223 334761    Fax:  +44 1223 334679
  51.